//   Copyright 2009 Pyxis Technologies
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//

using Pyxis.FluentSelenium.Locator;
using Selenium;

namespace Pyxis.FluentSelenium.Tester
{
    public class TableRowTester
    {
        private readonly ISelenium selenium;
        private readonly string locator;

        public TableRowTester(ISelenium selenium, string locator, int rowNumber)
        {
            this.selenium = selenium;
            this.locator = locator + string.Format("/tr[{0}]", rowNumber);
        }

        public void ShouldSee(params string[] columnContent)
        {
            for (var columnNumber = 1; columnNumber <= columnContent.Length; columnNumber++)
            {
                var cellLocator = GetCellLocator(columnNumber);
                var actualCellValue = selenium.GetText(cellLocator.ToString());
                var expectedValue = columnContent[columnNumber - 1];

                if (expectedValue != actualCellValue)
                    ConditionError.ContentNotMatch(expectedValue, actualCellValue, cellLocator);
                //Assert.AreEqual(columnContent[i], actualCellValue);
            }
        }

        private ElementLocator GetCellLocator(int columnNumber)
        {
            var cellLocatorFormat = "{0}/td[{1}]";
            var cellLocatorPath = string.Format(cellLocatorFormat, locator, columnNumber);
            return ElementLocator.WithXpath(cellLocatorPath);
        }

        public TableCellTester Column(int columnIndex)
        {
            return TableCellTester.Create(selenium, locator, columnIndex);
        }
    }
}
